<%@page import="com.MD5"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
    <%@page import="com.DBtools"%>
    <%@ page import="java.sql.*" %>
    
    <!--这是一个密码修改页面  -->
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta charset="UTF-8">
	<!-- 响应式布局标签：viewport-->
	<meta name="viewport"
		content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<!-- bootstrap css文件 -->
	<link rel="stylesheet" href="bootstrap-4.6.1-dist/css/bootstrap.min.css">
	<!-- 选项 1：jQuery 和 Bootstrap 集成包（集成了 Popper） -->
	<script
		src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"
		integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
		crossorigin="anonymous"></script>
	<script
		src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"
		integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct"
		crossorigin="anonymous"></script>

</head>
<h3>修改密码</h3>
<hr>
<style>
 .yanz{color:gray;font-size:12px;}

 </style>
<%
//接收教师账号修改信息
request.setCharacterEncoding("UTF-8");
String UserNum=null;


String orinpwd=(String) request.getSession().getAttribute("UserPwd");
UserNum=(String) request.getSession().getAttribute("UserNum");


String NewPwd=request.getParameter("NewPwd"); 

 if(NewPwd!=null)  NewPwd=new MD5().md5(NewPwd);//加密算法

String UserPwd=request.getParameter("UserPwd");

String sql="";
String num="";

if(NewPwd!=null &&UserPwd.equals(orinpwd)){

	sql = "update user set UserPwd='"+NewPwd+"' where UserNum ='"+UserNum+"'";
	int	r = new DBtools().execute(sql);
	System.out.println("修改成功");
	request.getSession().setAttribute("bol","yes");
	//response.sendRedirect("Loginout.jsp");
	
	response.sendRedirect("Loginout.jsp");
}
//out.println("sql="+sql+"<br>");	
%>
          
 <body>
<!-- 修改账号密码 -->
<%-- <br>
<form name="inputacc" class="form-inline">
<table width="300" align="center" border="1" class="imagetable">
<tr >
     <th colspan="2">修改个人密码</th>
        
  </tr>
<tr >
<td>账号</td>
<td><input name="TeaId"  id="TeaId" value="<%=UserNum%>"></td>
</tr>
<tr hidden="hidden">
<td></td>
<td><input name="orinpwd"  id="orinpwd" value="<%=orinpwd%>"></td>
</tr>
<tr>
<td>原密码</td>
<td><input type="password" name="UserPwd"  id="UserPwd" ></td>
</tr>

<tr>
<td>新密码</td>
<td><input class="NewPwd" type="password" name="NewPwd"  id="NewPwd" placeholder="密码位数在6~10之间">
</td>
</tr>
<tr>
<td>请再次输入密码</td>
<td><input type="password" name="ReNewPwd"  id="ReNewPwd" placeholder="请保持与新密码一致">
</td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="btn" value="修改" id="btn2" onclick="return check2(this.form)" ></td>

</tr>
 </table>
 </form>
  --%>
 
 <!-- 模态框:修改密码 -->
<div class="modal fade" id="updatePassword" tabindex="-1">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="line-height:20px;margin-top:-15px;margin-right:-10px;">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title position-absolute" id="exampleModalLabel" style="top:8px;left:12px;">修改密码</h4>
                </div>
                <div class="modal-body">
                    <form name="editForm">
                        <div class="form-group">
                            <label for="recipient-name">原密码：</label>
                            <input type="password" id="oldpassword" class="form-control" name="oldpassword" required placeholder="原密码">
                            <div style="display: inline" id="tip1"></div>
                        </div>
                        <div class="form-group">
                            <label for="message-text">新密码：</label>
                            <input type='password' id="password1" name="password1" class="form-control" required placeholder="长度为: 6-18">
                            <div style="display: inline" id="tip2"></div>
                        </div>
                        <div class="form-group">
                            <label for="message-text">确认密码：</label>
                            <input type='password' id="password2" name="password2" class="form-control" required placeholder="请再次输入新密码">
                            <div style="display: inline" id="tip3"></div>
                        </div>
                    </form>
                </div>
<div class="modal-footer">
<button onclick="submitPassword()" class="btn btn-primary" ng-disabled="editForm.$invalid">确定</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
 

<script type="text/javascript">

var ReNewPwd =document.querySelector("ReNewPwd");
var NewPwd= document.querySelector('input');

//var input = document.querySelector('NewPwd')
var men = document.querySelector('.yanz')
input.onfocus = function() {
    if (NewPwd.value.length<6) {
    	NewPwd.value = ''
    }
}
input.onblur = function() {
    if (NewPwd.value == '') {
    	NewPwd.style.border = '1px solid red'
        men.innerHTML = '请输入正确的手机号码'
        men.style.color = 'red'
    }
}


   function check2(form){
	   /* var TeaId= document.getElementById("TeaId").value; */
	   /*  var btn1= document.getElementById("btn1").value; */
	   /*  var btn2= document.getElementById("btn2").value; */
	  /*  alert(btn1); */
	   //alert(pwd);
	   
	  // var UserPwd=(String) request.getSession().getAttribute("UserPwd");
	    var ReNewPwd =document.getElementById("ReNewPwd").value;
       var NewPwd= document.getElementById("NewPwd").value; 
       var orinpwd= document.getElementById("orinpwd").value;
       var UserPwd= document.getElementById("UserPwd").value;
	   var btn2=document.inputacc.btn2.value;
	  // alert(btn2);
	   
	   	if(UserPwd!=orinpwd){
		   alert("原密码错误，请重新输入！");
		   document.inputacc.UserPwd.focus();
		   return false;
		   }
	   	else if(ReNewPwd.length<6 ||NewPwd !==ReNewPwd){
				   alert("密码不合法或不一致");
				   document.inputacc.ReNewPwd.focus();
				   document.inputacc.NewPwd.focus();
				   return false;
			   		} 
			   
	   /* 	else if(pwd.length <=0){   
	   	 	alert("该教师账号尚未注册，请先注册！");
		   	return false;
	   	} */
	   	else {
	   	 	alert("修改成功！");
	   		return true;
	   	}
	
	   
   	}

   
 

</script>


</body> 
 </html>